//
//  ZH_HomeCourceTableViewCell.m
//  WisdomStar
//
//  Created by zhangliwen on 2018/10/17.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_HomeCourceTableViewCell.h"
@interface ZH_HomeCourceTableViewCell()
@property (nonatomic,weak)UIView *bgView;
@property (nonatomic,weak)UIImageView *images;
@property (nonatomic,weak)UILabel *priceLabel;
@property (nonatomic,weak)UILabel *titleLabel;
@property (nonatomic,weak)UILabel *teacherLabel;
@property (nonatomic,weak)UIButton *typeButton;
@property (nonatomic,weak)UIButton *classButton;
@property (nonatomic,weak)UIButton *gradeButton;
@property (nonatomic,weak)UILabel *timeLabel;
@property (nonatomic,weak)UILabel *numLabel;
@property (nonatomic,weak)UIImageView *lookImage;
@end
@implementation ZH_HomeCourceTableViewCell

///创建
+(instancetype)cellWithTableView:(UITableView*)tableView
{
    static NSString *ID = @"ZH_HomeCourceTableViewCell";
    ZH_HomeCourceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell == nil){
        cell = [[ZH_HomeCourceTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}
///初始化
-(void)initDefault
{
    [self unShowClickEffect];
    
}
- (void)loadSubviewConstraints{
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(FITSCALE(9));
        make.left.equalTo(self.contentView).offset(FITSCALE(11));
        make.right.equalTo(self.contentView).offset(FITSCALE(-11));
        make.height.mas_equalTo(FITSCALE(128));
        make.bottom.equalTo(self.contentView);
    }];
    [self.images mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgView).offset(FITSCALE(10));
        make.left.equalTo(self.bgView.mas_left).offset(FITSCALE(10));
        make.width.mas_equalTo(FITSCALE(121));
        make.height.mas_equalTo(FITSCALE(103));
    }];
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.images);
        make.right.equalTo(self.bgView.mas_right).offset(FITSCALE(-11));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.images);
        make.left.equalTo(self.images.mas_right).offset(FITSCALE(12));
        make.right.equalTo(self.priceLabel.mas_left);
    }];
    [self.teacherLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(FITSCALE(19));
        make.left.equalTo(self.titleLabel);
    }];
    [self.typeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(FITSCALE(14));
        make.left.equalTo(self.teacherLabel.mas_right).offset(FITSCALE(10));
        make.width.mas_equalTo(FITSCALE(85));
        make.height.mas_equalTo(FITSCALE(22));
    }];
    [self.classButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.teacherLabel.mas_bottom).offset(FITSCALE(12));
        make.left.equalTo(self.titleLabel);
        make.width.mas_equalTo(FITSCALE(66));
        make.height.mas_equalTo(FITSCALE(22));
    }];
    [self.gradeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.teacherLabel.mas_bottom).offset(FITSCALE(12));
        make.left.equalTo(self.classButton.mas_right).offset(FITSCALE(9));
        make.width.mas_equalTo(FITSCALE(51));
        make.height.mas_equalTo(FITSCALE(22));
    }];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.classButton.mas_bottom).offset(FITSCALE(11));
        make.left.equalTo(self.titleLabel);
    }];
    [self.numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.timeLabel);
        make.right.equalTo(self.bgView.mas_right).offset(FITSCALE(-11));
    }];
    [self.lookImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.numLabel);
        make.right.equalTo(self.numLabel.mas_left).offset(FITSCALE(-4));
        make.width.mas_equalTo(FITSCALE(19));
        make.height.mas_equalTo(FITSCALE(14));
    }];
}
- (void)updateUI:(NSMutableDictionary *)data{
    if (data) {
        if(![data[@"image"] isKindOfClass:[NSNull class]]){
            [self.images sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVER_TEST,data[@"image"]]] placeholderImage:nil];
        }
        if(![data[@"course_name"] isKindOfClass:[NSNull class]]){
            self.titleLabel.text = [NSString stringWithFormat:@"%@",data[@"course_name"]];
        }
        if(![data[@"nickname"] isKindOfClass:[NSNull class]]){
            self.teacherLabel.text = data[@"nickname"];
        }
        if(![data[@"teach_type"] isKindOfClass:[NSNull class]]){
            NSString *string = [NSString stringWithFormat:@"%@",data[@"teach_type"]];
            if ([string isEqualToString:@"1"]) {
                [self.typeButton setTitle:@"一对一授课" forState:UIControlStateNormal];
            }
            else{
                 [self.typeButton setTitle:@"团体课程" forState:UIControlStateNormal];
            }
        }
        if(![data[@"name"] isKindOfClass:[NSNull class]]){
            [self.classButton setTitle:data[@"name"] forState:UIControlStateNormal];
        }
        if(![data[@"grade"] isKindOfClass:[NSNull class]]){
            [self.gradeButton setTitle:data[@"grade"] forState:UIControlStateNormal];
        }
        if(![data[@"create_at"] isKindOfClass:[NSNull class]]){
            self.timeLabel.text = data[@"create_at"];
        }
        if(![data[@"scan"] isKindOfClass:[NSNull class]]){
            self.numLabel.text = [NSString stringWithFormat:@"(%@)",data[@"scan"]];
        }
        if(![data[@"price"] isKindOfClass:[NSNull class]]){
            self.priceLabel.text = [NSString stringWithFormat:@"¥%@",data[@"price"]];
        }

        
    }
}
- (void)updataUI:(ZH_StudentListModel *)data{
    [self.images sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVER_TEST,data.image]]];
    self.titleLabel.text = data.name;
    self.teacherLabel.text = data.nickname;
    self.priceLabel.text = [NSString stringWithFormat:@"￥%@",data.price];
    if (data.teach_type == 1) {
        [self.typeButton setTitle:@"一对一授课" forState:UIControlStateNormal];
    }
    else{
        [self.typeButton setTitle:@"团体课程" forState:UIControlStateNormal];
    }
    [self.classButton setTitle:data.cate_name forState:UIControlStateNormal];
    [self.gradeButton setTitle:data.grade forState:UIControlStateNormal];
    self.timeLabel.text = data.create_at;

}
- (void)updatesUI:(NSDictionary *)data{
    if(![data[@"image"] isKindOfClass:[NSNull class]]){
        [self.images sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVER_TEST,data[@"image"]]] placeholderImage:nil];
    }
    if(![data[@"course_name"] isKindOfClass:[NSNull class]]){
        self.titleLabel.text = [NSString stringWithFormat:@"%@",data[@"course_name"]];
    }
    if(![data[@"nickname"] isKindOfClass:[NSNull class]]){
        self.teacherLabel.text = data[@"nickname"];
    }
    if(![data[@"teach_type"] isKindOfClass:[NSNull class]]){
        NSString *string = [NSString stringWithFormat:@"%@",data[@"teach_type"]];
        if ([string isEqualToString:@"1"]) {
            [self.typeButton setTitle:@"一对一授课" forState:UIControlStateNormal];
        }
        else{
            [self.typeButton setTitle:@"团体课程" forState:UIControlStateNormal];
        }
    }
    if(![data[@"name"] isKindOfClass:[NSNull class]]){
        [self.classButton setTitle:data[@"name"] forState:UIControlStateNormal];
    }
    if(![data[@"grade"] isKindOfClass:[NSNull class]]){
        [self.gradeButton setTitle:data[@"grade"] forState:UIControlStateNormal];
    }
    if(![data[@"create_at"] isKindOfClass:[NSNull class]]){
        self.timeLabel.text = data[@"create_at"];
    }
    if(![data[@"price"] isKindOfClass:[NSNull class]]){
        self.priceLabel.text = [NSString stringWithFormat:@"¥%@",data[@"price"]];
    }

}
- (void)updatessUI:(NSDictionary *)data{
    if(![data[@"image"] isKindOfClass:[NSNull class]]){
        [self.images sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVER_TEST,data[@"image"]]] placeholderImage:nil];
    }
    if(![data[@"course_name"] isKindOfClass:[NSNull class]]){
        self.titleLabel.text = [NSString stringWithFormat:@"%@",data[@"course_name"]];
    }
    if(![data[@"nickname"] isKindOfClass:[NSNull class]]){
        self.teacherLabel.text = data[@"nickname"];
    }
    if(![data[@"way"] isKindOfClass:[NSNull class]]){
        NSString *string = [NSString stringWithFormat:@"%@",data[@"way"]];
        if ([string isEqualToString:@"1"]) {
            [self.typeButton setTitle:@"一对一授课" forState:UIControlStateNormal];
        }
        else{
            [self.typeButton setTitle:@"团体课程" forState:UIControlStateNormal];
        }
    }
    if(![data[@"name"] isKindOfClass:[NSNull class]]){
        [self.classButton setTitle:data[@"name"] forState:UIControlStateNormal];
    }
    if(![data[@"start"] isKindOfClass:[NSNull class]]){
        self.timeLabel.text = data[@"start"];
    }
    if(![data[@"price"] isKindOfClass:[NSNull class]]){
        self.priceLabel.text = [NSString stringWithFormat:@"¥%@",data[@"price"]];
    }
   

}
- (void)updataClassUI:(NSDictionary *)data{
    if (data) {
        if(![data[@"image"] isKindOfClass:[NSNull class]]){
            [self.images sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVER_TEST,data[@"image"]]] placeholderImage:nil];
        }
        if(![data[@"course_name"] isKindOfClass:[NSNull class]]){
            self.titleLabel.text = [NSString stringWithFormat:@"%@",data[@"course_name"]];
        }
        if(![data[@"grade"] isKindOfClass:[NSNull class]]){
            [self.gradeButton setTitle:data[@"grade"] forState:UIControlStateNormal];
        }
        if(![data[@"course_price"] isKindOfClass:[NSNull class]]){
            self.priceLabel.text = [NSString stringWithFormat:@"¥%@",data[@"course_price"]];
        }
        if(![data[@"cate"] isKindOfClass:[NSNull class]]){
            [self.classButton setTitle:data[@"cate"] forState:UIControlStateNormal];
        }
        if(![data[@"teach_type"] isKindOfClass:[NSNull class]]){
            NSString *string = [NSString stringWithFormat:@"%@",data[@"teach_type"]];
            if ([string isEqualToString:@"1"]) {
                [self.typeButton setTitle:@"一对一授课" forState:UIControlStateNormal];
            }
            else{
                [self.typeButton setTitle:@"团体课程" forState:UIControlStateNormal];
            }
        }
    }
}
- (void)upclassUI:(NSDictionary *)data{
    if (data) {
        if(![data[@"teacher_name"] isKindOfClass:[NSNull class]]){
            self.teacherLabel.text = data[@"teacher_name"];
        }
    }
}
- (void)setHiddenGrade{
    self.gradeButton.hidden = YES;
}
#pragma mark - getter,setter
- (UIView *)bgView{
    if (!_bgView) {
        UIView *view = [UIView createViewWithBackgroundColor:kFontColorWhite];
        view.layer.cornerRadius = FITSCALE(3);
        view.layer.borderWidth = FITSCALE(1);
        view.layer.borderColor = [UIColor colorWithHexString:@"#DFDFDF"].CGColor;
        view.layer.masksToBounds = YES;
        view.clipsToBounds = YES;
        [self.contentView addSubview:_bgView = view];
    }
    return _bgView;
}
- (UIImageView *)images{
    if (!_images) {
        UIImageView *image = [UIImageView createImageViewWithName:@""];
        image.backgroundColor = kFontColorRed;
        image.layer.cornerRadius = FITSCALE(3);
        image.layer.masksToBounds = YES;
        image.clipsToBounds = YES;
        [self.contentView addSubview:_images = image];
    }
    return _images;
}
- (UILabel *)priceLabel{
    if (!_priceLabel) {
        UILabel *label = [UILabel createLabelWithText:@"￥29.90" font:kFontSize_26];
        label.textColor = [UIColor colorWithHexString:@"#FF4242"];
        label.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:_priceLabel = label];
    }
    return _priceLabel;
}
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        UILabel *label = [UILabel createLabelWithText:@"课程标题..." font:kFontSize_26];
        [self.contentView addSubview:_titleLabel = label];
    }
    return _titleLabel;
}
- (UILabel *)teacherLabel{
    if (!_teacherLabel) {
        UILabel *label = [UILabel createLabelWithText:@"李老师" font:kFontSize_26];
        label.textColor = [UIColor colorWithHexString:@"#555555"];
        [self.contentView addSubview:_teacherLabel = label];
    }
    return _teacherLabel;
}
- (UIButton *)typeButton{
    if (!_typeButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"一对一授课" target:self action:nil];
        [button setTitleColor:[UIColor colorWithHexString:@"#00C9AE"] forState:UIControlStateNormal];
        button.layer.cornerRadius = FITSCALE(10);
        button.layer.borderWidth = FITSCALE(1);
        button.layer.borderColor = [UIColor colorWithHexString:@"#00C9AE"].CGColor;
        button.layer.masksToBounds = YES;
        button.clipsToBounds = YES;
        button.titleLabel.font = kFontSize_26;
        [self.contentView addSubview:_typeButton = button];
    }
    return _typeButton;
}
- (UIButton *)classButton{
    if (!_classButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"音乐" target:self action:nil];
        button.backgroundColor = [UIColor colorWithHexString:@"#CBFFF8"];
        [button setTitleColor:[UIColor colorWithHexString:@"#00C9AE"] forState:UIControlStateNormal];
        button.layer.cornerRadius = FITSCALE(10);
        button.layer.borderWidth = FITSCALE(1);
        button.layer.borderColor = [UIColor colorWithHexString:@"#00C9AE"].CGColor;
        button.layer.masksToBounds = YES;
        button.clipsToBounds = YES;
        button.titleLabel.font = kFontSize_26;
        [self.contentView addSubview:_classButton = button];
    }
    return _classButton;
}
- (UIButton *)gradeButton{
    if (!_gradeButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"9年级" target:self action:nil];
        button.backgroundColor = [UIColor colorWithHexString:@"#FFD2CB"];
        [button setTitleColor:[UIColor colorWithHexString:@"#FF4646"] forState:UIControlStateNormal];
        button.layer.cornerRadius = FITSCALE(10);
        button.layer.borderWidth = FITSCALE(1);
        button.layer.borderColor = [UIColor colorWithHexString:@"#FF4646"].CGColor;
        button.layer.masksToBounds = YES;
        button.clipsToBounds = YES;
        button.titleLabel.font = kFontSize_26;
        [self.contentView addSubview:_gradeButton = button];
    }
    return _gradeButton;
}
- (UILabel *)timeLabel{
    if (!_timeLabel) {
        UILabel *label = [UILabel createLabelWithText:@"1天前" font:kFontSize_26];
        label.textColor = [UIColor colorWithHexString:@"#999999"];
        [self.contentView addSubview:_timeLabel = label];
    }
    return _timeLabel;
}
- (UILabel *)numLabel{
    if (!_numLabel) {
        UILabel *label = [UILabel createLabelWithText:@"(12)" font:kFontSize_26];
        label.textColor = [UIColor colorWithHexString:@"#999999"];
        label.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:_numLabel = label];
    }
    return _numLabel;
}
- (UIImageView *)lookImage{
    if (!_lookImage) {
        UIImageView *image = [UIImageView createImageViewWithName:@"icon_eyes"];
        [self.contentView addSubview:_lookImage = image];
    }
    return _lookImage;
}
@end
